package com.common.auth.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import com.common.api.annontation.ServiceLog;
import com.common.api.model.PageModel;
import com.common.auth.api.service.ResourceService;
import com.common.auth.api.dto.ResourceDto;

import com.common.web.annotation.ControllerRequest;
import com.common.web.dto.request.FuzzyPageDTO;
import com.common.web.dto.response.RestResponse;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * <p>
 * 资源前端控制器
 * </p>
 *
 * @author ficus
 */
@ServiceLog
@ControllerRequest("/resource/")
@Api(tags = "系统授权-资源服务接口")
public class ResourceController {

	@Autowired
	private ResourceService resourceService;
	
	/**
	 * @param fuzzyPageDTO
	 * @return
	 */
    @ApiOperation(value = "查询资源集合")
    @RequestMapping(value="queryList")
    public RestResponse queryList(@RequestBody FuzzyPageDTO fuzzyPageDTO) {
      	PageModel<ResourceDto> page= resourceService.queryList(fuzzyPageDTO);
        return RestResponse.success("查询资源集合成功!").setData(page);
    }
	
	/**
	 * @param fuzzyPageDTO
	 * @return
	 */
    @ApiOperation(value = "查询资源树集合")
    @RequestMapping(value="queryTreeList")
    public RestResponse queryTreeList() {
      	List<ResourceDto> page= resourceService.queryTreeList();
        return RestResponse.success("查询资源集合成功!").setData(page);
    }
    
	/**
	 * @param id
	 * @return
	 */
	@RequestMapping(value="get")
	@ApiOperation(value ="根据主键查询资源")
    public RestResponse get(@RequestBody String id) {
		ResourceDto dto= resourceService.get(id);	
		return RestResponse.success("根据主键查询资源成功!").setData(dto);
    }	
	
	/**
	 * @param ResourceDto
	 * @return
	 */
	@RequestMapping(value="save")
	@ApiOperation(value ="保存资源")
    public RestResponse save(@RequestBody ResourceDto dto) {
		int count= resourceService.saveDto(dto);	
        return RestResponse.success("保存资源成功!").setData(count);
    }
	
	/**
	 * @param idList
	 * @return
	 */
	@RequestMapping(value="dels")
	@ApiOperation(value ="根据主键批量删除资源")
    public RestResponse dels(@RequestBody List<String> idList) {
		int count= resourceService.dels(idList);	
		return RestResponse.success("根据主键批量删除资源成功!").setData(count);
    }
	
}
